package com.gxxy.spring.kp04_integration.cls02_transaction.s02_annotation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class AccountServiceImpl implements IAccountService {
	
	@Autowired
	private IAccountDao dao;

	@Override
	//@Transactional
	public void transfer(Long inId, Long outId, Double money) {
		// 开启事务
		this.transferOut(outId, money);
		/*@SuppressWarnings("unused")
		int res = 10 / 0;*/
		this.transferIn(inId, money);
		// 提交事务
		/*dao.transferOut(outId, money);
		@SuppressWarnings("unused")
		int res = 10 / 0;
		dao.transferIn(inId, money);*/
	}

	@Override
	//@Transactional
	public void transferIn(Long inId, Double money) {
		// 开启事务
		dao.transferIn(inId, money);
		// 提交事务
	}

	@Override
	//@Transactional
	public void transferOut(Long outId, Double money) {
		// 开启事务
		dao.transferOut(outId, money);
		// 提交事务
	}
	
}
